<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head th:replace="/common/head :: head" />
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
<!-- 配置grid -->
<div class="container"
     style="padding:  0px 10px !important; margin-top: -10px; text-align: center !important;">
    <div class="row">
        <div class="ibox float-e-margins">
            <input id="userId" th:value="${userId}" type="hidden">
            <div class="ibox-title">
                <h5 id="account" th:text="'账户：' + ${account}"></h5>
            </div>
            <div class="ibox-content">
                <ul id="zTree" class="ztree"></ul>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <button class="btn btn-sm btn-info" type="button" id="btn_save">
                <i class="ace-icon fa fa-check bigger-110"></i> 保存
            </button>
            &nbsp;
            <button class="btn btn-sm btn-danger" type="button" id="btn_close">
                <i class="ace-icon fa fa-close bigger-110"></i> 关闭
            </button>
        </div>
    </div>
</div>
</div>
<footer th:replace="/common/footer :: footer"></footer>
<script th:inline="javascript" type="text/javascript">
    $(function () {
        //获取窗口索引
        var index = parent.layer.getFrameIndex(window.name);
        $("#btn_close").bind("click", function () {
            parent.layer.close(index);
        });
        $("#btn_save").bind("click", function () {
            var appIds = Common.zTreeCheckedNodes("zTree");
            var ajax = new $ax(Common.ctxPath + "/user/setApp", function (result) {
                if (result.success) {
                    Common.success(result.message + "!");
                    window.parent.User.table.refresh();
                    parent.layer.close(index);
                } else {
                    Common.error(result.message + "!");
                }
            }, function (result) {
                Common.error(result.responseJSON.message + "!");
            });
            ajax.set("userId", $("#userId").val());
            ajax.set("appIds", appIds);
            ajax.start();
        });
        initZtree();
    });

    function initZtree() {
        var setting = {
            check: {
                enable: true,
                chkboxType: { "Y": "ps", "N": "ps" }
            },
            data: {
                simpleData: {
                    enable: true
                }
            }
        };
        var ztree = new $ZTree("zTree", "/tree/app/" + $("#userId").val());
        ztree.setSettings(setting);
        ztree.init();
    }
</script>
</body>
</html>
